package com.darly.rnmodule.component;

import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.facebook.react.ReactInstanceManager;

/**
 * Description TODO: 基础使用创建组件布局
 * Package com.darly.rnmodule.component
 * Author fronchdarly
 * Date 2021/5/26 5:04 PM
 * Where: 陕西西安
 * How: 特别一般的公司
 */
public abstract class BaseComponent extends LinearLayout implements ReactNativeView{

    public BaseComponent(Context context) {
        super(context);
        addView(initViews(context));
    }

    public BaseComponent(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public BaseComponent(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public BaseComponent(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    protected View initViews(Context context){
        int width = Resources.getSystem().getDisplayMetrics().widthPixels;
        LinearLayout root = new LinearLayout(context);
        root.setLayoutParams(new LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));
        root.addView(getComponentView(), new LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));
        return root;
    }

    protected abstract View getComponentView();

    @Override
    public Bundle getLaunchOptions() {
        return null;
    }

    @Override
    public String getCommonName() {
        return null;
    }

    @Override
    public ReactInstanceManager getInstanceManager() {
        return null;
    }

    @Override
    public void unMount() {

    }
}
